/*
 * Java CMPP API
 * Copyright (C) 2006 by Youming.Xu
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 526 Room, Hong Wa Building,22#,South Section1,
 * YiHuan Road,Sichuan,Chengdu,P.R.China
 * 
 * A copy of the LGPL can be viewed at http://www.gnu.org/copyleft/lesser.html
 * Java CMPP API author: xym008@gmail.net
 * Java CMPP API Homepage: http://cmppapi.sourceforge.net/
 * UnbindResp.java,v 1.10 2006-7-416:57:20 xuym Exp
 */

package com.bci.cmpp.message;

import com.bci.cmpp.CMPPConstants;
import com.bci.cmpp.util.CMPPIO;

/**
 * UnbindResp.java
 * 
 * @author xuym
 * @version 1.0
 * 
 */
public class CMPPTerminateResp extends CMPPResponse {

	/**
	 * 
	 */
	public CMPPTerminateResp() {
		super(CMPPConstants.CMPP_TERMINATE_RESP);
		this.totalLength = 12;
		this.buffer = new byte[this.totalLength];
		CMPPIO.intToBytes(this.totalLength, 4, this.buffer, 0);
		CMPPIO.intToBytes(this.commandId, 4, this.buffer, 4);
	}

	public CMPPTerminateResp(CMPPTerminate rq) {
		this();
		this.sequenceNum = rq.getSequenceNum();
	}

	public void readFrom(byte[] b, int offset)
			throws InvalidParameterValueException {
		if (b == null || b.length < this.totalLength + offset)
			throw new InvalidParameterValueException(
					"input data is not validate.", "");
		this.sequenceNum = CMPPIO.bytesToInt(b, 8 + offset, 4);
	}

	public byte[] getBytes() throws InvalidParameterValueException {
		this.buffer = new byte[this.totalLength];
		CMPPIO.intToBytes(this.totalLength, 4, this.buffer, 0);
		CMPPIO.intToBytes(this.commandId, 4, this.buffer, 4);
		CMPPIO.intToBytes(this.sequenceNum, 4, this.buffer, 8);
		return this.buffer;
	}

	public void validate() throws InvalidParameterValueException {

	}
}
